function thousandBitSeparator (str) {
  if (!str || isNaN(str)) {
    str = 0;
  }
  str = String(parseFloat(str).toFixed(2));
  let postfix = '';
  if (str.indexOf('.') >= 0) {
    postfix = str.substring(str.indexOf('.'));
    str = str.substring(0, str.indexOf('.'));
  } else {
    postfix = '';
  };
  // console.log(postfix);
  // .99
  // console.log(str);
  // 9999999999999
  let iNum = str.length % 3;
  let prev = '';
  let iNow = 0;
  let temp = '';
  let arr = [];
  if (iNum !== 0) {
    prev = str.substring(0, iNum);
    arr.push(prev);
  }
  str = str.substring(iNum);
  for (let i = 0; i < str.length; i++) {
    iNow++;
    temp += str[i];
    if (iNow === 3 && temp) {
      arr.push(temp);
      temp = '';
      iNow = 0;
    }
  }
  // console.log(arr);
  // ["9", "999", "999", "999", "999"]
  return arr.join(',') + postfix;
}

export default thousandBitSeparator;
